package com.hxn.wxshake.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hxn.wxshake.utils.UrlParamUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

/**
 * @ClassName WXCallBack
 * @Description 微信回调接口处理
 * @Author hxn
 * @Date 2019/8/6 14:05
 * @Version 1.0
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WXCallBack {

    public final static int SUCCESS = 2000;

    private String uuid;
    private String username;
    private String nickname;
    private String avatar;
    private String blog;
    private String company;
    private String location;
    private String email;
    private String remark;
    private String gender;
    private String source;
    private String token;

    public static WXCallBack getByObject(final Object data){
        JSONObject responseData = (JSONObject) JSONObject.toJSON(data);
        return JSON.toJavaObject(responseData,WXCallBack.class);
    }
    //这儿使用全路径，因为redirect会使https转成http
    public String getJumpWXShakePageUrl(final String urlHead){
        StringBuilder jumpPageUrlSB = new StringBuilder();
        jumpPageUrlSB.append(urlHead).append("/index")
                .append("?")
                .append("openId=").append(uuid).append("&")
                .append("username=").append(UrlParamUtil.getUrlParam(username,"UTF-8")).append("&")
                .append("gender=").append(gender);
        return jumpPageUrlSB.toString();
    }
}
